package com.ruoyi.operation.order.shop.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.operation.order.shop.domain.Shop;
import com.ruoyi.operation.order.shop.service.IShopService;
import com.ruoyi.project.system.dept.domain.Dept;
import com.ruoyi.project.system.dept.service.IDeptService;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author king
 * @create 2019/4/16 14:05
 */
@Controller
@RequestMapping(value = "/shop/shop")
public class ShopController extends BaseController {


    // 定义一个跳转到页面的路径
    private String prefix = "order/shop/";

    @Autowired
    private IShopService iShopService;

    @Autowired
    private IDeptService iDeptService;

    /**
     * 跳转到店铺页面
     * @return
     */
    @RequiresPermissions(value = "shop:shop:shop")
    @GetMapping()
    String shop(){
        return prefix + "shop";
    }

    /**
     * 查询所有的店铺信息
     * @param shop
     * @return
     */
    @RequestMapping(value = "/list")
    @RequiresPermissions(value = "shop:shop:shop")
    @ResponseBody
    public TableDataInfo allShopList(Shop shop){
        startPage();
        List<Shop> shopList = iShopService.allShopList(shop);
        return getDataTable(shopList);
    }



    /**
     * 跳转到店铺新增的页面
     * @return
     */
    @RequiresPermissions(value = "shop:shop:add")
    @RequestMapping(value = "/add")
    String add(){
        return  prefix + "add";
    }

    /**
     * 新增店铺信息
     * @param shop
     * @return
     */
    @RequestMapping(value = "/saveShop")
    @RequiresPermissions(value = "shop:shop:add")
    @ResponseBody
    public AjaxResult saveShop(Shop shop){
        return toAjax(iShopService.saveShop(shop));
    }

    /**
     * 跳转到编辑的页面
     * @param id
     * @param model
     * @param shop
     * @return
     */
    @RequiresPermissions(value = "shop:shop:edit")
    @RequestMapping(value = "/edit/{id}")
    String edit(@PathVariable("id") String id, Model model,Shop shop){
        if (null != id || id != "" ){
            shop = iShopService.findById(id);
        }
        List<Dept> deptList = iDeptService.allDeptList();
        model.addAttribute("shop",shop);
        model.addAttribute("deptList",deptList);
        return prefix + "edit";
    }

    /**
     * 编辑店铺信息
     * @param shop
     * @return
     */
    @RequiresPermissions("shop:shop:edit")
    @RequestMapping(value = "editShop")
    @ResponseBody
    public AjaxResult editShop(Shop shop){
        return toAjax(iShopService.editShop(shop));
    }

    /**
     * 删除店铺信息
     * @param id
     * @return
     */
    @RequestMapping(value = "/remove/{id}")
    @RequiresPermissions(value = "shop:shop:remove")
    @ResponseBody
    public AjaxResult delShop(@PathVariable("id") String id){
        return toAjax(iShopService.delShop(id));
    }




    /**
     * 查询所有的平台
     * @return
     */
    @RequestMapping(value = "/allDeptT")
    @ResponseBody
    public List<Dept> allDeptT(){
        return iDeptService.allDeptList();
    }


}
